package com.jay.cloudstudy.ui.home

import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.jay.cloudstudy.ui.home.HomeBannerAdapter.HomeBannerViewHolder
import com.jay.image.ImageLoader
import com.youth.banner.adapter.BannerAdapter

/**
 *
 * @author zhouxu
 * @email 1419982188@qq.com
 * @date 2021/7/5
 */
class HomeBannerAdapter(datas: MutableList<HomeBannerBean>?) :
    BannerAdapter<HomeBannerBean, HomeBannerViewHolder>(datas) {

    class HomeBannerViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
    }

    override fun onCreateHolder(parent: ViewGroup?, viewType: Int): HomeBannerViewHolder {
        val imageView = ImageView(parent!!.context)
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        imageView.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        imageView.scaleType = ImageView.ScaleType.CENTER_CROP
        return HomeBannerViewHolder(imageView)
    }

    override fun onBindView(
        holder: HomeBannerViewHolder?,
        data: HomeBannerBean?,
        position: Int,
        size: Int
    ) {
        data?.also {
            ImageLoader.load(holder?.itemView as ImageView, it.url)
        }
    }
}